package com.csjbot.weedle_auto.base

import android.content.Context
import android.os.Bundle
import android.support.v4.app.FragmentActivity
import android.view.View
import android.view.inputmethod.InputMethodManager

import com.csjbot.weedle_auto.file.constants_util.Constants
import com.csjbot.weedle_auto.fragment.bean.AdioCheckBean
import com.csjbot.weedle_auto.fragment.bean.StationBean
import com.csjbot.weedle_auto.util.SharePreferenceTools

/**
 * Created by chenqi on 8/4/17.
 * } catch (SecurityException e) {
 * Csjlogger.info("You do not have read/write permission to the serial port");
 * } catch (IOException e) {
 * Csjlogger.info("The serial port can not be opened for an unknown   reason.");
 * } catch (InvalidParameterException e) {
 * Csjlogger.info("Please configure your serial port first.");
 * }
 */

abstract class BaseActivity : FragmentActivity() {
    private val TAG = "chenqi"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(resureID)
        //注册监听
        initView()
        initPager()
    }


    protected abstract val resureID: Int

    protected open fun initView() {}

    protected open fun initPager() {}

    //    @Override
    //    protected void onDestroy() {
    //        super.onDestroy();
    //        new SharePreferenceTools(this).remove(Constants.CHECKINFOR);
    //        Csjlogger.info("chenqi onResume print destory");
    //    }

    public override fun onStart() {
        super.onStart()
        //        Csjlogger.info(TAG, "start onStart~~~");
    }


    public override fun onResume() {
        super.onResume()
        SharePreferenceTools(this).putModel(Constants.CHECKINFOR, AdioCheckBean())
        SharePreferenceTools(this).putModel(Constants.SLAMSTATIONBEAN, StationBean())
        //        Csjlogger.info(TAG, "start onResume~~~");
    }

    public override fun onPause() {
        super.onPause()
        //        Csjlogger.info(TAG, "start onPause~~~");
    }

    public override fun onStop() {
        super.onStop()
        //        Csjlogger.info(TAG, "start onStop~~~");
    }

    public override fun onDestroy() {
        super.onDestroy()
        //        Csjlogger.info(TAG, "start onDestroy~~~");
    }

    public override fun onRestart() {
        super.onRestart()
        //        Csjlogger.info(TAG, "start onRestart~~~");
    }

    fun closeIMM(view: View) {
        val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
        imm.showSoftInput(view, InputMethodManager.SHOW_FORCED)
        imm.hideSoftInputFromWindow(view.windowToken, 0) //强制隐藏键盘
    }
}
